﻿#include "StdAfx.h"
#include "SRObjModelLoader.h"

using namespace sora;
using std::string;
using std::vector;
using std::auto_ptr;

TEST(ObjModelParser, split)
{
	vector<string> tokenStrList;

	//1줄 테스트
	string line = "mtllib cube.mtl";
	EXPECT_TRUE(line.length() > 0);
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(2, tokenStrList.size());
	EXPECT_STREQ("mtllib", tokenStrList[0].c_str());
	EXPECT_STREQ("cube.mtl", tokenStrList[1].c_str());

	line = "usemtl red";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(2, tokenStrList.size());
	EXPECT_STREQ("usemtl", tokenStrList[0].c_str());
	EXPECT_STREQ("red", tokenStrList[1].c_str());

	line = "";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(0, tokenStrList.size());

	line = "# 0 materials";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(0, tokenStrList.size());

	line = "vn 0.577350 0.577350 -0.577350";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(4, tokenStrList.size());
	EXPECT_STREQ("vn", tokenStrList[0].c_str());
	EXPECT_STREQ("0.577350", tokenStrList[1].c_str());
	EXPECT_STREQ("0.577350", tokenStrList[2].c_str());
	EXPECT_STREQ("-0.577350", tokenStrList[3].c_str());

	line = "f 1//1 2//2 3//3 4//4";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(13, tokenStrList.size());
	EXPECT_STREQ("f", tokenStrList[0].c_str());
	EXPECT_STREQ("1", tokenStrList[1].c_str());
	EXPECT_STREQ("//", tokenStrList[2].c_str());
	EXPECT_STREQ("1", tokenStrList[3].c_str());
	EXPECT_STREQ("2", tokenStrList[4].c_str());
	EXPECT_STREQ("//", tokenStrList[5].c_str());
	EXPECT_STREQ("2", tokenStrList[6].c_str());

	line = "f 1/1 2/2 3/3";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(10, tokenStrList.size());
	EXPECT_STREQ("f", tokenStrList[0].c_str());
	EXPECT_STREQ("1", tokenStrList[1].c_str());
	EXPECT_STREQ("/", tokenStrList[2].c_str());
	EXPECT_STREQ("1", tokenStrList[3].c_str());
	EXPECT_STREQ("2", tokenStrList[4].c_str());
	EXPECT_STREQ("/", tokenStrList[5].c_str());
	EXPECT_STREQ("2", tokenStrList[6].c_str());

	line = "f 11/11/11 2/2/2 3/3/3 4/4/4";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(21, tokenStrList.size());
	EXPECT_STREQ("f", tokenStrList[0].c_str());
	EXPECT_STREQ("11", tokenStrList[1].c_str());
	EXPECT_STREQ("/", tokenStrList[2].c_str());
	EXPECT_STREQ("11", tokenStrList[3].c_str());
	EXPECT_STREQ("/", tokenStrList[4].c_str());
	EXPECT_STREQ("11", tokenStrList[5].c_str());
	EXPECT_STREQ("2", tokenStrList[6].c_str());

	line = "f 72//129 47//83 30//66";
	tokenStrList = ObjModelParser::parser().split(line);
	EXPECT_EQ(10, tokenStrList.size());
	EXPECT_STREQ("30", tokenStrList[7].c_str());
	EXPECT_STREQ("//", tokenStrList[8].c_str());
	EXPECT_STREQ("66", tokenStrList[9].c_str());

}

TEST(ObjModelLoader, getModelNodeData)
{
	ObjModelLoader loader;
	vector<string> lines;
	lines.push_back("# 0 materials");
	lines.push_back("vn 0.577350 0.577350 -0.577350");
	lines.push_back("f 1/1 2/2 3/3");

	vector<ObjNodeData*> datalist;
	loader.getModelNodeData(lines, datalist);
	EXPECT_EQ(2, datalist.size());

	ObjNodeData::destroy(datalist);
}
